$.extend(planner.dialogs, {
    saveMech: {
        show: function ()
        {
            $("#txtSaveThisMechName").val( planner.mech.name );
            $( "#dialog-save-mech" ).dialog({ height: 190, modal: true, autoOpen: false });
            $( "#dialog-save-mech" ).dialog( "open" ); 
        },
        save_this_mech: function () { 
            console.log("planner.dialogs.saveMech_click()");
            planner.server.post_mech( 
                { 
                    n: $("#txtSaveThisMechName").val(), a: 's',
                }, 
                function(data) {}, 
                function(data) {
                    $( "#dialog-save-mech" ).dialog("close");
                    
                    $(".post").hide();
                    planner.garage.ui.update("name", function(){ $("#garage").show(); });
                },
                true
            );
            $( "#dialog-save-mech" ).dialog("close");
        },
        ui:
        {
            setup: function()
            {
                
            },
            init: function()
            {
                $('#txtSaveThisMechName').keypress(function(e) {
                    if (e.keyCode == $.ui.keyCode.ENTER) {
                        planner.dialogs.saveMech.save_this_mech();
                    }
                });
                
                $("#btnSaveThisMech").button().click( planner.dialogs.saveMech.save_this_mech );
                
                
                $("#btnSaveThisMechCancel").button().click(
                    function () { 
                        $( "#dialog-save-mech" ).dialog("close");                
                    }
                );
                
                $("#btnSaveThisMechRandomName").click(
                    function () { 
                        $.ajax({ url: "/n" }).done( function(data) {
                             $("#txtSaveThisMechName").val(data);
                             $('#txtSaveThisMechName').focus();
                        });
                    }
                );
                
                $(document).on("dialogopen", "#dialog-save-mech", function(event, ui) {
                    setTimeout(function() {
                        $("#txtSaveThisMechName").focus();
                    },100);
                    
                });
                
            }
        }
    }
});